/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nuce.entity;

import dataaccess.DataAccess;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author LINHNC
 */
public class QuestionSet {
    private Question[] item;
    private int n;
    public QuestionSet(){
        n = 0; item = null;
    }
    public Question getItem(int i){
        return item[i];
    }
    public int getCount(){
        return n;
    }
    public void SelectByLevel(int level){
        final String procName = "Question_SelectByLevel";
        final String procNameCount = "Question_SelectCountByLevel";
        
        DataAccess da = new DataAccess();
        String[] args = new String[1];
        args[0] = Integer.toString(level);
        ResultSet rs = da.executeProc(procNameCount, args);
        if (rs != null) {
            try {
                rs.next();
                this.n = Integer.parseInt(rs.getString(1));
                item = new Question[n];
                rs = da.executeProc(procName, args);
                int i=0;
                while (rs.next()){
                    item[i] = new Question();
                    item[i].setContent(rs.getString("content"));
                    item[i].setAnswer1(rs.getString("answer1"));
                    item[i].setAnswer1(rs.getString("answer2"));
                    item[i].setAnswer1(rs.getString("answer3"));
                    item[i].setAnswer1(rs.getString("answer4"));
                    item[i].setLevel(Integer.parseInt(rs.getString("level")));
                    i++;
                }
                
                
            } catch (SQLException ex) {
                Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
            
            }
        }
    }
    public static void main(String[] args){
        QuestionSet q = new QuestionSet();
        q.SelectByLevel(2);
        int i=0;
        for (i=0; i<q.getCount(); i++)
        System.out.println(q.getItem(i).getContent());
        
    }
}
